import { _decorator, Component, EditBox, instantiate, Node, Prefab } from "cc";
import { PrefabPathEnum } from "../../Enum";
import DataManager from "../../global/DataManager";
import { ResourceManager } from "../../utils/ResourceManager";
import { EntityTypeEnum } from "../../common";
import { TableManager } from "./TableManger";

const { ccclass, property } = _decorator;
@ccclass('HallManager')
export class HallManager extends Component {




    async onLoad() {
        await this.loadRes()
        this.createTables()
    }


    async loadRes() {
        const pList = []
        for (const type in PrefabPathEnum) {
            const p = ResourceManager.Instance.loadRes(PrefabPathEnum[type], Prefab).then((prefab) => {
                DataManager.Instance.prefabMap.set(type, prefab)
            })
            pList.push(p)
        }
        await Promise.all(pList)

    }

    createTables() {
        const tables = DataManager.Instance.state.tables;
        tables.forEach(() => {
            const prefab = DataManager.Instance.prefabMap.get(EntityTypeEnum.Table);
            const table = instantiate(prefab)
            table.getComponent(TableManager).init()
            this.node.addChild(table)
        })


    }

}

